package com.hsnn.medstgmini.dao.impl;

import java.util.Date;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.base.dict.dao.impl.BaseHibernateDAO;
import com.hsnn.medstgmini.dao.SysPubHolidayDao;
import com.hsnn.medstgmini.model.SysPubHoliday;

/**
 * @category 公共假日DAO实现类
 * @author 韩守松
 * @date 2015年11月24日
 */
@Repository
public class SysPubHolidayDaoImpl  extends BaseHibernateDAO implements SysPubHolidayDao{

	/**
	 * @category 获取工作日转假日的日期
	 * @author 韩守松
	 * @date   2015年11月24日
	 * @param  @param date
	 * @param  @return
	 */
	public SysPubHoliday getWorkToHolidayDay(Date date) {
		StringBuffer hql = new StringBuffer();
		hql.append("SELECT pub_hod_id,day,type,remark,upd_user,upd_datetime FROM sys_pub_holiday where day = :date and (type = 1 or type =0 ) ");
		SQLQuery query = getSession().createSQLQuery(hql.toString());
		query.setDate("date", date);
		query.addEntity(SysPubHoliday.class);
		return (SysPubHoliday)query.uniqueResult();
	}

	public SysPubHoliday getHolidayToWorkDay(Date date) {
		StringBuffer hql = new StringBuffer();
		hql.append("SELECT pub_hod_id,day,type,remark,upd_user,upd_datetime  FROM sys_pub_holiday where day = :date and type=2 ");
		SQLQuery query = getSession().createSQLQuery(hql.toString());
		query.setDate("date", date);
		query.addEntity(SysPubHoliday.class);
		return (SysPubHoliday)query.uniqueResult();
	}

}
